﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMessaging.Address;
using MMessaging.Address.Services;
using MMessaging.Test.Fahrstuhl.Engine;
using TUtils;

namespace MMessaging.Test.Fahrstuhl.ElevatorEngine
{
	public class ElevatorEngine : TSingleton<ElevatorEngine>
	{
		public MAddress ServiceAddress
		{
			get;
			private set;
		}
		public MAddress SwitchAddress
		{
			get;
			private set;
		}
		public MServiceSwitch Switch
		{
			get;
			private set;
		}
		private const int INTERVALLTIME_ALIFE_MESSAGE = 2000;
		private const int Max_count_of_threads = 100;
		private const string LOG_NAME_OF_MESSAGE_HANDLER = "ElevatorServiceHandler";
		private ElevatorService _service;

		public ElevatorEngine()
		{
			ServiceAddress = new MAddress("{2000AD29-709C-4FC1-9F76-BF9504740525}");
			SwitchAddress = new MAddress("{734FA6AD-DF1C-4233-BFC3-24BA752623CF}");

			Switch = new MServiceSwitch();
			Switch.Init(
				startAtOnce:false,
				thisAddress:SwitchAddress);

			_service = new ElevatorService(
				serviceAddress:ServiceAddress,
				intervallTimeAlifeMessage:INTERVALLTIME_ALIFE_MESSAGE);
			_service.Init(
				loggingNameOfService: LOG_NAME_OF_MESSAGE_HANDLER,
				node: Switch,
				maxCountOfThreads: Max_count_of_threads,
				startAtOnce:true);

			// Switch.StartAsync();
		}
	}
}
